<template>
	<view class="course-type-list">
		<!-- 标题 -->
		<module-title :title="title"></module-title>
		<!-- 列表区域 -->
		<view class="course-list">
			<!-- 课程的每一项 -->
			<view class="course-item" v-for="item in list" @click="detail(item.courseId)" :key="item.courseId">
				<!-- 课程封面 -->
				<image :src="item.coverFileUrl" mode=""></image>
				<!-- 课程标题 -->
				<view class="course-title">
					{{item.courseTitle}}
				</view>
				<!-- 描述 -->
				<view class="course-intro">
					<!-- 免费付费 -->
					<view class="free-text" v-if="item.isFree">
						免费
					</view>
					<!-- 打折课程 -->
					<view class="course-discount-price" v-else-if="item.isDiscount">
						<view class="course-price-money">
							{{item.discountPrice}}
						</view>
						
						<view class="old-price">
							{{item.coursePrice}}
							<text></text>
						</view>
					
					</view>
					<!-- 不免费也不打折 -->
					<view class="course-price-money" v-else>
						{{item.coursePrice}}
					</view>

					<!-- 观看人数 -->
					<view class="learning-num">
						{{item.learningNum}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	// title
	// type,根据不同的type获取不同的接口，加载不同的数据
	// num: 加载多少条
	import ModuleTitle from '../../../components/module-title/module-title.vue'
	import {
		getCourseListByType
	} from "../../../api/course-api.js"
	export default {
		components: {
			ModuleTitle
		},
		props: {
			title: String,
			type: String,
			num: Number
		},
		data() {
			return {
				list: []
			}
		},
		created() {
			getCourseListByType(this.type).then(res => {
				this.list = res.data.rows
			})
		},
		methods:{
			detail(id){
				uni.navigateTo({
					url:`/pages/course-detail/course-detail?id=${id}`
				})
			}
		}
	}
</script>

<style lang="scss">
	.course-type-list {
		padding: 20rpx 20rpx 0;

		.course-list {
			display: flex;
			flex-wrap: wrap;

			.course-item {
				width: 50%;
				box-sizing: border-box;
				padding: 15rpx 10rpx 15rpx 10rpx;

				image {
					width: 100%;
					height: 200rpx;
					border-radius: 8rpx;
				}

				// 标题
				.course-title {
					height: 94rpx;
					margin-top: 10rpx;
					font-size: 32rpx;
					overflow: hidden;
					display: -webkit-box; //将对象作为弹性伸缩盒子模型显示;
					text-overflow: ellipsis; //溢出部分用省略号代替
					-webkit-line-clamp: 2; //设置文本显示两行
					-webkit-box-orient: vertical; //从上到下排列子元素;
					white-space: normal;
				}

				// 课程介绍
				.course-intro {
					font-size: 26rpx;
					display: flex;
					justify-content: space-between;
				}

				.free-text {
					color: #13ce66;
				}

				.course-discount-price {
					display: flex;

					.old-price {
						margin-left: 15rpx;
						color: #cccccc;
						position: relative;

						text {
							top: 0;
							bottom: 50%;
							left: 0;
							right: 0;
							position: absolute;
							border-bottom: 1rpx solid #cccccc;
						}
					}

				}

				.course-price-money {
					color: #ffa605;
				}

			}
		}
	}
</style>
